<?php
/*
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the BSD License.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 */

/**
 * This file contains all of the global utility functions for the Google
 * Checkout package.
 * 
 * @package GoogleCheckout
 * @author Byrne Reese <byrne@majordojo.com>
 * @copyright 2006-2008, Byrne Reese.
 */

/**
 * Used to digitally sign the cart's XML contents.
 * 
 * @param string The key used to generate the SHA1 Hash
 * @param string The string to encrypt.
 * @return string The encrypted string
 */
function CalcHmacSha1($key,$data) {
  $blocksize=64;
  $hashfunc='sha1';
  if (strlen($key)>$blocksize)
    $key=pack('H*', $hashfunc($key));
  $key=str_pad($key,$blocksize,chr(0x00));
  $ipad=str_repeat(chr(0x36),$blocksize);
  $opad=str_repeat(chr(0x5c),$blocksize);
  $hmac = pack(
      'H*',$hashfunc(
		     ($key^$opad).pack(
				       'H*',$hashfunc(
						      ($key^$ipad).$data
						      )
				       )
		     )
      );
  return $hmac;
}
?>
